<?php
declare (strict_types = 1);

namespace app\product\service;

use app\product\model\ProductAttrValueModel;

class ProductAttrValueService extends BaseService
{
    public function __construct(ProductAttrValueModel $productAttrValueModel)
    {
        $this->productAttrValueModel = $productAttrValueModel;
    }

    public function model(){
        return $this->productAttrValueModel;
    }

    public function list(array $where = [] , array $limit = [], array $sort= []){
        $limit = check_limit($limit);
        $sort = check_sort($sort);
        return $this->productAttrValueModel->where($where)->limit($limit['page'],$limit['pagesize'])->order($sort[0],$sort[1])->select();
    }

    public function select(array $where = [],$field = ['*'],array $whereIn = []){
        $model = $this->productAttrValueModel::with([ProductAttrValueModel::WITH_ATTR_NAME]);
        $model = $model->field($field)->where($where);
        if(!empty($whereIn)) $model->whereIn($whereIn[0],$whereIn[1]);
        return $model->select();
    }

    public function count(array $where = []){
        return $this->productAttrValueModel->where($where)->count();
    }

    public function find(array $where = []){
        return $this->productAttrValueModel->where($where)->find();
    }

    public function value(array $where = [], string $column = ''){
        return $this->productAttrValueModel->where($where)->value($column);
    }

    public function insertGetId(array $data = []){
        return $this->productAttrValueModel->insertGetId($data);
    }

    public function update(array $where = [],array $data = []){
        return $this->productAttrValueModel->where($where)->update($data);
    }

    public function deleteBatch(array $whereIn = []){
        return $this->productAttrValueModel->whereIn($whereIn[0],$whereIn[1])->delete();
    }
}
